package threaddemo3;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2022-08-06
 * Time: 18:09
 */
//测试
public class Testdemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Mycallable m1=new Mycallable();
        //需要一个中间类的实例来传参，就是futureTask实例
        //可以获取线程执行完毕之后的结果.也可以作为参数传递给Thread对象
        //查看手册可知，futuretask继承了runnable接口
        FutureTask<String> f=new FutureTask<String>(m1);
        
        
        //不能直接把callable实例作为参数，因为callable方法没有继承runnable接口
        Thread t1=new Thread(f);
        //获取线程执行完毕的结果
        String s=f.get();
        t1.start();
        System.out.println(s);
    }
}
